load("//tools/build_defs/android:fb_xplat_android_cxx_library.bzl", "fb_xplat_android_cxx_library")
load("//tools/build_defs/oss:profilo_defs.bzl", "profilo_path")

fb_xplat_android_cxx_library(
    name = "print_visitor",
    srcs = [
        "PrintEntryVisitor.cpp",
    ],
    header_namespace = "profilo/writer",
    exported_headers = [
        "PrintEntryVisitor.h",
    ],
    compiler_flags = [
        "-fexceptions",
        "-frtti",
        "-DLOG_TAG=\"Profilo/Writer\"",
    ],
    labels = [],
    preferred_linkage = "static",
    tests = [
        profilo_path("cpp/test:codegen"),
    ],
    visibility = [
        profilo_path("cpp/test/..."),
        profilo_path("facebook/cpp/test/..."),
    ],
    exported_deps = [
        profilo_path("cpp/generated:cpp"),
        profilo_path("deps/fmt:fmt"),
    ],
)

fb_xplat_android_cxx_library(
    name = "delta_visitor",
    srcs = [
        "DeltaEncodingVisitor.cpp",
    ],
    header_namespace = "profilo/writer",
    exported_headers = [
        "DeltaEncodingVisitor.h",
    ],
    compiler_flags = [
        "-fexceptions",
        "-frtti",
        "-DLOG_TAG=\"Profilo/Writer\"",
        # no __builtin_sub/add_overflow on gcc 4.9, so let's do this instead
        "-fwrapv",
    ],
    labels = [],
    preferred_linkage = "static",
    tests = [
        profilo_path("cpp/test:delta_visitor"),
    ],
    visibility = [
        profilo_path("cpp/test/..."),
        profilo_path("facebook/cpp/test/..."),
    ],
    exported_deps = [
        profilo_path("cpp/generated:cpp"),
    ],
)

fb_xplat_android_cxx_library(
    name = "timestamp_truncating_visitor",
    srcs = [
        "TimestampTruncatingVisitor.cpp",
    ],
    header_namespace = "profilo/writer",
    exported_headers = [
        "TimestampTruncatingVisitor.h",
    ],
    compiler_flags = [
        "-fexceptions",
        "-frtti",
        "-DLOG_TAG=\"Profilo/Writer\"",
    ],
    labels = [],
    preferred_linkage = "static",
    visibility = [
        profilo_path("cpp/test/..."),
        profilo_path("facebook/cpp/test/..."),
    ],
    exported_deps = [
        profilo_path("cpp/generated:cpp"),
    ],
)

fb_xplat_android_cxx_library(
    name = "stack_visitor",
    srcs = [
        "StackTraceInvertingVisitor.cpp",
    ],
    header_namespace = "profilo/writer",
    exported_headers = [
        "StackTraceInvertingVisitor.h",
    ],
    compiler_flags = [
        "-fexceptions",
        "-frtti",
        "-DLOG_TAG=\"Profilo/Writer\"",
    ],
    labels = [],
    preferred_linkage = "static",
    visibility = [
        profilo_path("cpp/test/..."),
    ],
    deps = [
        profilo_path("cpp/profiler:constants"),
    ],
    exported_deps = [
        profilo_path("cpp/generated:cpp"),
    ],
)

fb_xplat_android_cxx_library(
    name = "packet_reassembler",
    srcs = [
        "PacketReassembler.cpp",
    ],
    header_namespace = "profilo/writer",
    exported_headers = [
        "PacketReassembler.h",
    ],
    compiler_flags = [
        "-fexceptions",
        "-frtti",
        "-DLOG_TAG=\"Profilo/Writer\"",
    ],
    labels = [],
    preferred_linkage = "static",
    visibility = [
        profilo_path("cpp/test/..."),
    ],
    exported_deps = [
        profilo_path("cpp/logger:logger"),
    ],
)

fb_xplat_android_cxx_library(
    name = "writer",
    srcs = [
        "TraceLifecycleVisitor.cpp",
        "TraceWriter.cpp",
    ],
    headers = [
        "ScopedThreadPriority.h",
        "TraceLifecycleVisitor.h",
    ],
    header_namespace = "profilo/writer",
    exported_headers = [
        "AbortReason.h",
        "TraceCallbacks.h",
        "TraceWriter.h",
    ],
    compiler_flags = [
        "-fexceptions",
        "-frtti",
        "-DLOG_TAG=\"Profilo/Writer\"",
    ],
    labels = [],
    preferred_linkage = "static",
    tests = [
        profilo_path("cpp/test:trace_writer"),
    ],
    visibility = [
        profilo_path("facebook/cpp/blackbox:crash_dump_writer"),
        profilo_path("cpp/mmapbuf/writer:trace_writer"),
        profilo_path("cpp/jni/..."),
        profilo_path("cpp/test/..."),
        profilo_path("facebook/cpp/test/..."),
    ],
    deps = [
        ":delta_visitor",
        ":packet_reassembler",
        ":print_visitor",
        ":stack_visitor",
        ":timestamp_truncating_visitor",
        ":trace_backwards",
        ":trace_file_helpers",
        profilo_path("cpp/logger:logger"),
        profilo_path("cpp/mmapbuf:buffer"),
        profilo_path("cpp/util:util"),
    ],
    exported_deps = [
        profilo_path("cpp/generated:cpp"),
    ],
)

fb_xplat_android_cxx_library(
    name = "trace_backwards",
    srcs = [
        "trace_backwards.cpp",
    ],
    header_namespace = "profilo/writer",
    exported_headers = [
        "trace_backwards.h",
    ],
    compiler_flags = [
        "-fexceptions",
        "-frtti",
        "-DLOG_TAG=\"Profilo/Writer\"",
    ],
    labels = [],
    preferred_linkage = "static",
    visibility = [
        profilo_path("cpp/jni/..."),
    ],
    deps = [
        ":packet_reassembler",
        profilo_path("cpp/generated:cpp"),
        profilo_path("cpp/logger:logger"),
    ],
)

fb_xplat_android_cxx_library(
    name = "trace_headers",
    srcs = [
        "trace_headers.cpp",
    ],
    header_namespace = "profilo/writer",
    exported_headers = [
        "trace_headers.h",
    ],
    compiler_flags = [
        "-fexceptions",
        "-frtti",
        "-DLOG_TAG=\"Profilo/Writer\"",
    ],
    labels = [],
    preferred_linkage = "static",
    visibility = [
        profilo_path("cpp/..."),
        profilo_path("facebook/cpp/..."),
    ],
    deps = [
        profilo_path("cpp/util:util"),
    ],
)

fb_xplat_android_cxx_library(
    name = "trace_file_helpers",
    srcs = [
        "TraceFileHelpers.cpp",
    ],
    header_namespace = "profilo/writer",
    exported_headers = [
        "TraceFileHelpers.h",
    ],
    compiler_flags = [
        "-fexceptions",
        "-frtti",
        "-DLOG_TAG=\"Profilo/Writer\"",
    ],
    labels = [],
    preferred_linkage = "static",
    visibility = [
        profilo_path("cpp/..."),
        profilo_path("facebook/cpp/..."),
    ],
    deps = [
        profilo_path("cpp/util:util"),
        profilo_path("deps/zstr:zstr"),
    ],
)
